import Server from "@/config/server";
import request from '@/utils/request';
import { showErrors, showError, showSuccess } from '@/utils/showMsg';

const state = {
  requestCode : false,  //状态码
  dataLists: [],      //列表数据
  Fields: [],         //列表标题

};
const actions = {
  //列表
  getLists({commit}, page) {
    request.get(Server.action.login_list, { params: page })
    .then(response => {
      console.log(response);
        if (response.data.errorCode === 0) {
            commit("setLists", response.data.result.list);
            let fields = response.data.result.fields;
            fields[0].width = 60
            fields.forEach(function (item, i) {
              item.dataIndex = fields[i].key
              item.align = 'center';
              item.width = item.width || 90
              // if(i < fields.length-1) {
              // }
            })
            commit("setFields", fields);
        } else {

        }
    })
  },
};
const mutations = {
  setErrorCode(state, text) {
	    state.requestCode = text;
	},
	setLists(state, lists) {
	    state.dataLists = lists;
	},
  setFields(state, lists) {
	    state.Fields = lists;
	},
};
export default {
    namespaced: true,
    state,
    actions,
    mutations
};
